//
//  ZTLSwitchViewController.m
//  Demo0032
//
//  Created by zTercel on 13-3-30.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import "ZTLSwitchViewController.h"
#import "ZTLBlueViewController.h"
#import "ZTLYellowViewController.h"

@interface ZTLSwitchViewController ()

@end

@implementation ZTLSwitchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
	self.blueViewController	= [[ZTLBlueViewController alloc]initWithNibName:@"BlueView" bundle:nil];
	[self.view insertSubview:self.blueViewController.view atIndex:0];
}

- (void)didReceiveMemoryWarning			
{
    [super didReceiveMemoryWarning];
    // Disposeof any resources that can be recreated.
	if (nil == self.blueViewController.view.superview) {
		self.blueViewController		= nil;
	} else {
		self.yellowViewController	= nil;
	}
}

-(IBAction) switchView:(id)sender
{
	[UIView beginAnimations:@"View Flip" context:nil];
	[UIView animateWithDuration:2.25 animations:nil];
		//[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	if (nil == self.yellowViewController.view.superview) {
		if (nil == self.yellowViewController) {
			self.yellowViewController = [[ZTLYellowViewController alloc]initWithNibName:@"YellowView" bundle:nil];
		}
		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
							   forView:self.view cache:YES];
			//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view catch: YES];
		[self.blueViewController.view removeFromSuperview];
		[self.view insertSubview:self.yellowViewController.view atIndex:0];
	} else {
		self.blueViewController = [[ZTLBlueViewController alloc]initWithNibName:@"BlueView" bundle:nil];
		
		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache: YES];
		[self.yellowViewController.view removeFromSuperview];
		[self.view insertSubview:self.blueViewController.view atIndex:0];
	}
	[UIView commitAnimations];
}

@end
